// 导入axios
import service from '@/utils/request'

// /admin/product/{page}/{limit}  获取spu分页数据

// /admin/product/spuImageList/8205 获取图片列表
//  /admin/product/spuSaleAttrList/8205 获取销售属性列表

// 图片类型规范
export interface SpuImageData {
  name?: string
  url?: string
  id?: number
  imgName: string
  imgUrl: string
  spuId?: number
  response?: any
  // isDefault?: string
  isDefault?: boolean
}
// 属性值列表类型规范
export interface SpuSaleAttrValueData {
  baseSaleAttrId: number | string
  id?: number
  isChecked?: string
  saleAttrName?: string
  saleAttrValueName: string | undefined
  spuId?: number
}
// spuSaleattrList 类型接口规范 表格中每一条对象
export type SpuSaleAttrData = {
  attrIdValId?: string
  baseSaleAttrId: number | string
  id?: number
  saleAttrName: string
  spuId?: number
  spuSaleAttrValueList: SpuSaleAttrValueData[]
  inputVisible?: boolean
  inputValue?: string
}

// 定义接口--> 请求分页器数据返回的主体内容类型接口规范

export interface SpuInfoListModel {
  category3Id: number | undefined
  description: string
  id?: number
  spuImageList: SpuImageData[]
  spuName: string
  spuSaleAttrList: SpuSaleAttrData[]
  tmId: number | undefined
}

// 定义接口--> 请求分页器数据返回的data类型接口规范
export interface SpuInfoDataModel {
  currwent: number
  pages: number
  size: number
  total: number
  records: SpuInfoListModel[]
}

// 定义接口--> 请求分页器返回的接口类型规范
export interface SpuInfoModel {
  code: number
  data: SpuInfoDataModel
}
/**
 * @desc 获取spu分页数据
 * @param page 当前页码
 * @param limit 每页显示多少条数据
 * @returns Promise
 */
export const getSpuInfo = (page: number, limit: number, category3Id: number) => {
  return service.get<any, SpuInfoModel>(`/admin/product/${page}/${limit}?category3Id=${category3Id}`)
}

// 销售属性下拉数据类型规范 -- 展示内容规范

export interface saleAttrListModel {
  id: number
  name: string
}

// 销售属性的下拉数据类型规范 -- 整体响应结果
export interface saleAttrModel {
  code: number
  data: saleAttrListModel[]
}

/**
 * @desc 获取销售属性的下拉数据
 * @returns Promise
 */
export const BaseSaleAttrList = () => {
  return service.get<any, saleAttrModel>('/admin/product/baseSaleAttrList')
}

// 新增数据的类型规范

export interface saveSpuModel {
  code: number
  data: SpuInfoListModel
}

/**
 * @desc 新增Spu数据
 * @param SpuInfo 收集好的表单数据
 * @returns Promise
 */
export const saveSpuinfo = (SpuInfo: SpuInfoListModel) => {
  return service.post<any, saveSpuModel>('/admin/product/saveSpuInfo', SpuInfo)
}
///admin/product/spuImageList/8370 获取图片列表接口
// /admin/product/spuImageList/3
///admin/product/spuSaleAttrList/8370 获取销售属性接口
// /admin/product/spuSaleAttrList/8392
/**
 * @desc 根据id获取图片的数据
 * @param spuId
 * @returns Promise
 */
export const spuImageList = (spuId: number) => {
  return service.get(`/admin/product/spuImageList/${spuId}`)
}

/**
 * @desc 根据id获取销售属性的数据
 * @param spuId
 * @returns Promise
 */
export const spuSaleAttrList = (spuId: number) => {
  return service.get(`/admin/product/spuSaleAttrList/${spuId}`)
}

// /admin/product/updateSpuInfo

/**
 * @desc 点击编辑再进行保存时使用
 * @returns Promise
 */
export const updateSpuInfo = (SpuInfo: SpuInfoListModel) => {
  return service.post<any, saveSpuModel>(`/admin/product/updateSpuInfo`, SpuInfo)
}

// /admin/product/deleteSpu/8413

// 定义删除接口的返回值类型规范

export interface DeleteSpuModel {
  code: number
  data: null
}

/**
 * @desc 删除一列数据 --> 删除一列SPU
 * @param rowId 当前表格中点击的您一列数据的id
 * @returns Promise
 */
export const deleteSpu = (rowId: number) => {
  return service.delete<any, DeleteSpuModel>(`/admin/product/deleteSpu/${rowId}`)
}

// ------------------------------------ 新增 SKU 页面的 api

// /admin/product/attrInfoList/1/1/1
